<html>
<head><meta charset="utf-8"><title>problem with criterion · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/problem.20with.20criterion.html">problem with criterion</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="214068061"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/problem%20with%20criterion/near/214068061" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/problem.20with.20criterion.html#214068061">(Oct 21 2020 at 15:34)</a>:</h4>
<p>I am switching from std benchmarking to criterion, and rust analyzer is freaking out and marking everything with a red underline </p>
<div class="codehilite" data-code-language="JSON"><pre><span></span><code><span class="p">{</span>
    <span class="nt">"resource"</span><span class="p">:</span> <span class="s2">"/c:/Users/finkelman/Documents/MyProjects/pubgrub-rs/benches/large_case.rs"</span><span class="p">,</span>
    <span class="nt">"owner"</span><span class="p">:</span> <span class="s2">"rustc"</span><span class="p">,</span>
    <span class="nt">"code"</span><span class="p">:</span> <span class="s2">"E0601"</span><span class="p">,</span>
    <span class="nt">"severity"</span><span class="p">:</span> <span class="mi">8</span><span class="p">,</span>
    <span class="nt">"message"</span><span class="p">:</span> <span class="s2">"`main` function not found in crate `large_case`\nconsider adding a `main` function to `benches\\large_case.rs`"</span><span class="p">,</span>
    <span class="nt">"source"</span><span class="p">:</span> <span class="s2">"rustc"</span><span class="p">,</span>
    <span class="nt">"startLineNumber"</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span>
    <span class="nt">"startColumn"</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
    <span class="nt">"endLineNumber"</span><span class="p">:</span> <span class="mi">39</span><span class="p">,</span>
    <span class="nt">"endColumn"</span><span class="p">:</span> <span class="mi">26</span>
<span class="p">}</span>
</code></pre></div>

<p>main is provided by <code>criterion_main</code></p>



<a name="214068133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/problem%20with%20criterion/near/214068133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/problem.20with.20criterion.html#214068133">(Oct 21 2020 at 15:34)</a>:</h4>
<p>Is this a known issue?</p>



<a name="214069116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/problem%20with%20criterion/near/214069116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/problem.20with.20criterion.html#214069116">(Oct 21 2020 at 15:40)</a>:</h4>
<p>I think it works for me:</p>
<p><a href="/user_uploads/4715/BIjrrbwA79zDu669E5HI4FKv/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/BIjrrbwA79zDu669E5HI4FKv/image.png" title="image.png"><img src="/user_uploads/4715/BIjrrbwA79zDu669E5HI4FKv/image.png"></a></div>



<a name="214069329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/problem%20with%20criterion/near/214069329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/problem.20with.20criterion.html#214069329">(Oct 21 2020 at 15:42)</a>:</h4>
<p>Hmmm... that is odd.</p>



<a name="214069575"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/problem%20with%20criterion/near/214069575" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/problem.20with.20criterion.html#214069575">(Oct 21 2020 at 15:43)</a>:</h4>
<p>Got it! My benchmarks use serde which is an optional feature. So I added <code>#![cfg(feature = "serde")]</code><br>
That is what triggers it</p>



<a name="214069814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/problem%20with%20criterion/near/214069814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/problem.20with.20criterion.html#214069814">(Oct 21 2020 at 15:45)</a>:</h4>
<p>Does putting that on the <code>criterion_group!</code> work?</p>



<a name="214069921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/problem%20with%20criterion/near/214069921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/problem.20with.20criterion.html#214069921">(Oct 21 2020 at 15:46)</a>:</h4>
<p>Because it's certainly missing <code>main</code> if you put it on the whole file and the feature is disabled</p>



<a name="214069964"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/problem%20with%20criterion/near/214069964" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/problem.20with.20criterion.html#214069964">(Oct 21 2020 at 15:46)</a>:</h4>
<p>Right makes sense.</p>



<a name="214070248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/problem%20with%20criterion/near/214070248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/problem.20with.20criterion.html#214070248">(Oct 21 2020 at 15:48)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[cfg(not(feature = </span><span class="s">"serde"</span><span class="cp">))]</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">eprintln</span><span class="o">!</span><span class="p">(</span><span class="s">"please run benmarks with --all-features"</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>

<p>Thanks for the help!</p>



<a name="214070270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/problem%20with%20criterion/near/214070270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/problem.20with.20criterion.html#214070270">(Oct 21 2020 at 15:48)</a>:</h4>
<p>You can also put the feature in <code>rust-analyzer.cargo.features</code></p>



<a name="214070570"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/problem%20with%20criterion/near/214070570" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/problem.20with.20criterion.html#214070570">(Oct 21 2020 at 15:50)</a>:</h4>
<p>this way a new contributor that runs <code>cargo bench</code> will get a helpful error message.</p>



<a name="214093828"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/problem%20with%20criterion/near/214093828" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/problem.20with.20criterion.html#214093828">(Oct 21 2020 at 18:29)</a>:</h4>
<p><span class="user-mention" data-user-id="120179">@Eh2406</span> isn't this the job for <code>required-features</code> feature of Cargo?</p>



<a name="214094086"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/problem%20with%20criterion/near/214094086" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/problem.20with.20criterion.html#214094086">(Oct 21 2020 at 18:31)</a>:</h4>
<p>Grate point!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>